import urllib.request as req

url = 'https://weibo.com/u/5885242254'
header = {
# ':authority': 'weibo.cn',
# ':method': 'GET',
# ':path': '/6451491586/info',
# ':scheme': 'https',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
# 'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'max-age=0',
#     cookie中携带着你的登陆信息   如果有登陆之后的cookie  那么我们就可以携带着cookie进入到任何页面
'cookie': 'UOR=www.baidu.com,weibo.com,www.baidu.com; SINAGLOBAL=4382047521725.1274.1620725283102; PC_TOKEN=6468361efb; XSRF-TOKEN=D3A-2mJ9L6TfvlHy7-dNegB6; login_sid_t=38cc213c4ef813ce830e42f9e49493b5; cross_origin_proto=SSL; wb_view_log=1536*8641.25; _s_tentry=weibo.com; Apache=8963871295620.854.1667800440121; ULV=1667800440125:14:1:1:8963871295620.854.1667800440121:1652197931031; WBtopGlobal_register_version=2022110713; SSOLoginState=1667800620; SUB=_2A25ObO58DeRhGeNG41cT9CzOzjiIHXVtrvI0rDV8PUJbkNAKLVmhkW1NSwC1TTltUPlcOd4qKNmcWdMQjlkQwqJ8; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWB0u1k8Fj8uFdTapsdcZC-5NHD95Qf1hnfeoBEeo-XWs4DqcjZHc8VMfLGP057eBtt; WBPSESS=a5ggl9Lx6JljOvZ8U2Vz8WWOmztjyw7mKhlzKIgmCR4p85-01vHL3s_sqAJQgEJ6h5Y7j0mEdIb0i0UBNhK47FJy_b3UkMXXZKOwlGB6ifoHRtdNX-sb0gkkvfTk0_btU6FbI1f3MdnXJd5IcwPevg==',
# referer  判断当前路径是不是由上一个路径进来的    一般情况下 是做图片防盗链
'referer': 'https://weibo.cn/',
'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
}
request=req.Request(url=url,headers=header)
res = req.urlopen(request)
con = res.read().decode("utf-8")
with open(file="weibo.html",mode="w",encoding="utf-8") as fp:
    fp.write(con)
